<template>
  <div class="app-container">
    <el-card>
      <h4>浏览记录</h4>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="看过我" name="1">
          <el-table :data="browseSawItList" style="width: 100%">
            <el-table-column
              prop="prop"
              label=""
              width="width"
              type="selection"
            >
            </el-table-column>
            <el-table-column prop="prop" label="基本信息" width="width">
              <template slot-scope="scope">
                <div style="display: flex">
                  <div class="portraitImg">
                    <img
                      :src="
                        scope.row.photoImg === 0
                          ? scope.row.photoUrl
                          : 'https://blwcompany.nbblmc.cn' + scope.row.photoUrl
                      "
                      alt=""
                    />
                  </div>
                  <div style="margin-left: 10px">
                    <div>
                      <div style="color: #409eff">{{ scope.row.fullname }}</div>
                    </div>
                    <div>
                      {{ scope.row.age }}岁 | {{ scope.row.educationText }} |
                      {{ scope.row.experienceText }}经验 |
                      {{ scope.row.sexText }}
                    </div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="prop"
              label="求职意向"
              width="240"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  effect="dark"
                  :content="scope.row.intentionJobs"
                  placement="top"
                  :hide-after="0"
                >
                  <div class="ellipsis">
                    想找 <span style="color: #409eff">{{
                      scope.row.intentionJobs
                    }}</span> 工作
                  </div>
                </el-tooltip>
                <el-tooltip
                  effect="dark"
                  :content="scope.row.intentionDistrict"
                  placement="bottom"
                  :hide-after="0"
                >
                  <div class="ellipsis">
                    想在 <span style="color: #409eff">{{
                      scope.row.intentionDistrict
                    }}</span> 工作
                  </div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="intentionJobs"
              label="浏览职位"
            >
            </el-table-column>
            <el-table-column
              prop="prop"
              label="浏览时间"
              width="width"
              align="center"
            >
              <template slot-scope="scope">
                {{ scope.row.addtime | dateFormat }}
              </template>
            </el-table-column>
            <!-- <el-table-column prop="prop" label="操作" width="300" align="center">
              <template>
                <el-button type="primary" size="small" @click="viewResume"
                  >查看简历</el-button
                >
              </template>
            </el-table-column> -->
          </el-table>
          <el-row
            :gutter="10"
            type="flex"
            justify="end"
            style="margin-top: 20px"
          >
            <el-pagination
              background
              @size-change="handleSizeLookChange"
              @current-change="handleCurrentLookChange"
              :page-sizes="[10, 20, 30, 50]"
              layout="total, sizes, prev, pager, next, jumper"
              :total="lookeMeTotal"
            >
            </el-pagination>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="我看过" name="2">
          <el-table :data="seenMyList" style="width: 100%">
            <el-table-column prop="prop" label="" width="50" type="selection">
            </el-table-column>
            <el-table-column prop="prop" label="基本信息" width="width">
              <template slot-scope="scope">
               <div style="display: flex">
                  <div class="portraitImg">
                    <img
                      :src="
                        scope.row.photoImg === 0
                          ? scope.row.photoUrl
                          : 'https://blwcompany.nbblmc.cn' + scope.row.photoUrl
                      "
                      alt=""
                    />
                  </div>
                  <div style="margin-left: 10px">
                    <div>
                      <div style="color: #409eff">{{ scope.row.fullname }}</div>
                    </div>
                    <div>
                      {{ scope.row.age }}岁 | {{ scope.row.educationText }} |
                      {{ scope.row.experienceText }}经验 |
                      {{ scope.row.sexText }}
                    </div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="intentionJobs"
              label="求职意向"
              width="240"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  effect="dark"
                  :content="scope.row.intentionJobs"
                  placement="top"
                  :hide-after="0"
                >
                  <div class="ellipsis">
                    想找 <span style="color: #409eff">{{
                      scope.row.intentionJobs
                    }}</span> 工作
                  </div>
                </el-tooltip>
                <el-tooltip
                  effect="dark"
                  :content="scope.row.intentionDistrict"
                  placement="bottom"
                  :hide-after="0"
                >
                  <div class="ellipsis">
                    想在 <span style="color: #409eff">{{
                      scope.row.intentionDistrict
                    }}</span> 工作
                  </div>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="addtime"
              label="浏览时间"
              width="width"
              align="center"
            >
              <template slot-scope="scope">
                {{ scope.row.addtime | dateFormat }}
              </template>
            </el-table-column>
            <!-- <el-table-column align="center" prop="prop" label="操作">
              <el-button type="primary" size="small">下载简历</el-button>
            </el-table-column> -->
            <!-- <el-table-column prop="prop" label="操作" width="width">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="mini"
                  @click="VviewResume(scope.row)"
                  >查看简历</el-button
                >
              </template>
            </el-table-column> -->
          </el-table>
          <el-row
            :gutter="10"
            style="margin-top: 20px"
            type="flex"
            justify="end"
          >
            <el-pagination
              background
              @size-change="handleSizeLookeMeChange"
              @current-change="handleCurrentLookMeChange"
              :page-sizes="[10, 20, 30, 50]"
              layout="total, sizes, prev, pager, next, jumper"
              :total="lookTotal"
            >
            </el-pagination>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-card>

    <!-- 查看简历 -->
    <el-dialog
      :visible.sync="viewVisible"
      width="500px"
      custom-class="resume-preview-dialog"
    >
      <div class="resume-preview">
        <!-- Header -->
        <div class="preview-header">
          <div class="user-info">
            <el-avatar
              :size="50"
              src="/placeholder.svg?height=50&width=50"
            ></el-avatar>
            <div class="basic-info">
              <div class="name-row">
                <span class="name">裕女士</span>
                <el-tag size="small" type="warning">今日活跃</el-tag>
              </div>
              <div class="sub-info">49岁 | 无经验 | 高中</div>
            </div>
          </div>
          <div class="actions">
            <i class="el-icon-star-off"></i>
            <i class="el-icon-share"></i>
            <i class="el-icon-close" @click="handleClose"></i>
          </div>
        </div>

        <!-- Job Status -->
        <div class="info-section">
          <div class="label">求职状态：</div>
          <div class="content">目前在职，但考虑换个新环境</div>
        </div>

        <!-- Job Intention -->
        <div class="info-section">
          <div class="label">求职意向</div>
          <div class="content">
            <div class="intention-item">
              <span class="item-label">期望职位：</span>
              <span>育婴师/保育员，人事/行政/后勤</span>
            </div>
            <div class="intention-item">
              <span class="item-label">期望地区：</span>
              <span>威海山，小港</span>
            </div>
            <div class="intention-item">
              <span class="item-label">期望薪资：</span>
              <span>3500~4000</span>
            </div>
          </div>
        </div>

        <!-- Contact Info -->
        <div class="info-section">
          <div class="label">联系方式</div>
          <el-alert type="info" :closable="false" class="contact-alert">
            <div class="contact-notice">
              联系电话：请先登录北仑人才招聘上查看联系方式，谢谢！
            </div>
          </el-alert>
        </div>

        <!-- Self Introduction -->
        <div class="info-section">
          <div class="label">自我描述</div>
          <div class="content description">这个人很懒，暂未填写自我描述...</div>
        </div>

        <!-- Footer Actions -->
        <div class="preview-footer">
          <div class="left-actions">
            <el-button size="small" plain @click="handleExport">
              <i class="el-icon-download"></i>
              导出
            </el-button>
            <el-button size="small" plain @click="handlePrint">
              <i class="el-icon-printer"></i>
              打印
            </el-button>
            <el-button size="small" plain @click="handleReport">
              <i class="el-icon-warning-outline"></i>
              举报
            </el-button>
          </div>
          <div class="right-actions">
            <el-button size="small" type="info" @click="handleChat"
              >聊一聊</el-button
            >
            <el-button size="small" type="success" @click="handleDownload"
              >下载简历</el-button
            >
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { viewRecordISawItApi, viewRecordLookAtMeApi } from "@/api/jlManage";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      activeName: "1",
      list: [
        {
          id: 1472,
          resume_id: 134,
          addtime: 1730446806,
          fullname: "周女士",
          display_name: 0,
          high_quality: 0,
          birthday: "1986-2",
          sex: 2,
          education: 5,
          enter_job_time: 1141142400,
          photo_img: 0,
          current: 244,
          specialty: "",
          tag: "",
          companyname: "宁波晟名电子有限公司",
          jobname: "业务助理",
          tag_list: [],
          sex_text: "女",
          education_text: "大专",
          experience_text: "18年经验",
          current_text: "无业在家",
          recent_work: "业务助理",
          age: 38,
          intention_trade: "",
          intention_jobs: "仓库管理员",
          intention_wage: "4500-5000",
          intention_district: "北仑",
          intention_nature: "全职",
          photo_img_src:
            "http:\/\/hr.blwang.com\/upload\/resource\/empty_photo_2.png",
          resume_link_url_web: "http:\/\/hr.blwang.com\/resume\/134.html",
        },
        {
          id: 1454,
          resume_id: 1392,
          addtime: 1730338701,
          fullname: "王女士",
          display_name: 0,
          high_quality: 0,
          birthday: "1971-9",
          sex: 2,
          education: 1,
          enter_job_time: 1727712000,
          photo_img: 0,
          current: 241,
          specialty: "",
          tag: "",
          companyname: "开店",
          jobname: "老板",
          tag_list: [],
          sex_text: "女",
          education_text: "初中",
          experience_text: "1个月经验",
          current_text: "目前已离职，可快速到岗",
          recent_work: "老板",
          age: 53,
          intention_trade: "",
          intention_jobs: "缝纫工",
          intention_wage: "4500-8000",
          intention_district: "北仑",
          intention_nature: "全职",
          photo_img_src:
            "http:\/\/hr.blwang.com\/upload\/resource\/empty_photo_2.png",
          resume_link_url_web: "http:\/\/hr.blwang.com\/resume\/1392.html",
        },
        {
          id: 1455,
          resume_id: 1227,
          addtime: 1730338605,
          fullname: "杨女士",
          display_name: 0,
          high_quality: 0,
          birthday: "1992-9",
          sex: 2,
          education: 1,
          enter_job_time: 1406822400,
          photo_img: 0,
          current: 242,
          specialty: "",
          tag: "",
          companyname: "北仑怡人玩具",
          jobname: "检验",
          tag_list: [],
          sex_text: "女",
          education_text: "初中",
          experience_text: "10年经验",
          current_text: "目前在职，但考虑换个新环境",
          recent_work: "检验",
          age: 32,
          intention_trade: "",
          intention_jobs: "操作工",
          intention_wage: "5500-7000",
          intention_district: "新碶",
          intention_nature: "全职",
          photo_img_src:
            "http:\/\/hr.blwang.com\/upload\/resource\/empty_photo_2.png",
          resume_link_url_web: "http:\/\/hr.blwang.com\/resume\/1227.html",
        },
      ],
      // 浏览记录我看过
      seenMyQuery: {
        uid: "",
        page: 1,
        pagesize: 10,
      },
      // 浏览记录看过我
      browseSawItQuery: {
        page: 1,
        pagesize: 10,
        uid: "",
      },
      viewVisible: false,
      VviewResumeList: {},
      // 看过我
      lookTotal: "",
      // 我看过
      lookeMeTotal: "",
      seenMyList: [],
      browseSawItList: [],
    };
  },
  created() {
    this.seenMyQuery.uid = this.userId;
    this.browseSawItQuery.uid = this.userId;
    this.viewRecordISawIt();
    this.viewRecordISawItByMe();
  },
  computed: {
    ...mapGetters(["userId"]),
  },
  watch: {
    // activeName(newVal, old) {
    //   console.log(newVal);
    //   if (newVal === "2") {
    //     this.browseSawItQuery.uid = this.userId;
    //     this.browseSawIt();
    //   }
    // },
  },
  methods: {
    // 查看简历
    viewResume() {},
    // 浏览记录我看过
    async viewRecordISawIt() {
      const res = await viewRecordISawItApi(this.seenMyQuery);
      this.seenMyList = res.records;
      this.lookTotal = res.total;
      console.log(this.seenMyList);
    },
    // 浏览记录看过我
    async viewRecordISawItByMe() {
      const res = await viewRecordLookAtMeApi(this.browseSawItQuery);
      console.log(res);
      this.browseSawItList = res.records;
      console.log(this.browseSawItList);
      this.lookeMeTotal = res.total;
      console.log(this.browseSawItList);
    },
    // 查看简历
    VviewResume(row) {
      console.log(row);
      // this.VviewResume = row;
      this.viewVisible = true;
    },
    // 分页
    handleSizeLookeMeChange(val) {
      this.seenMyQuery.pagesize = val;
      this.viewRecordISawIt();
    },
    // 点击页码改变时候
    handleCurrentLookMeChange(val) {
      this.seenMyQuery.page = val;
      this.viewRecordISawIt();
    },
    handleSizeLookChange(val) {
      this.browseSawItQuery.pagesize = val;
      this.viewRecordISawItByMe();
    },
    // 点击页码改变时候
    handleCurrentLookChange(val) {
      this.browseSawItQuery.page = val;
      this.viewRecordISawItByMe();
    },
    notes() {},
    // 删除
    delBtn() {
      this.$confirm("确定删除该查看记录吗？", "系统提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.portraitImg {
  img {
    border-radius: 50%;
    width: 52px;
    height: 52px;
  }
}

.resume-preview-dialog {
  :deep(.el-dialog__header) {
    display: none;
  }

  :deep(.el-dialog__body) {
    padding: 0;
  }
}

.resume-preview {
  padding: 20px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;

  .user-info {
    display: flex;
    gap: 12px;
  }

  .basic-info {
    .name-row {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 4px;
    }

    .name {
      font-size: 16px;
      font-weight: 500;
      color: #303133;
    }

    .sub-info {
      font-size: 14px;
      color: #909399;
    }
  }

  .actions {
    display: flex;
    gap: 16px;
    color: #909399;
    font-size: 20px;

    i {
      cursor: pointer;
      &:hover {
        color: #409eff;
      }
    }
  }
}

.info-section {
  margin-bottom: 20px;

  .label {
    font-size: 14px;
    color: #606266;
    margin-bottom: 8px;
  }

  .content {
    color: #303133;
    font-size: 14px;
    line-height: 1.5;
  }
}

.intention-item {
  margin-bottom: 8px;

  .item-label {
    color: #909399;
  }
}

.contact-alert {
  background-color: #f5f7fa;
  border: none;

  :deep(.el-alert__content) {
    padding: 0;
  }
}

.contact-notice {
  font-size: 14px;
  color: #909399;
}

.description {
  color: #909399;
  font-style: italic;
}

.preview-footer {
  margin-top: 30px;
  display: flex;
  justify-content: space-between;
  padding-top: 20px;
  border-top: 1px solid #ebeef5;

  .left-actions,
  .right-actions {
    display: flex;
    gap: 12px;
  }

  :deep(.el-button) {
    [class^="el-icon-"] {
      margin-right: 4px;
    }
  }
}

.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 220px; // 设置稍小于列宽，留出一些边距
  margin: 0 auto; // 居中显示
}
</style>
